#include <iostream>
#include <stack>
using namespace std;
const int N = 1e5 + 10;
int pushed[N], poped[N];
int t;
// 模拟栈的操作入栈和出栈，最后查看栈是否为空
int main()
{
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        for(int i = 0;i < n;i++) cin >> pushed[i];
        for(int i = 0;i < n;i++) cin >> poped[i];

        stack<int> st;
        int top = 0;
        for(int i = 0;i < n;i++)
        {
            st.push(pushed[i]);
            // 注意出栈条件
            while(top < n && !st.empty() && st.top() == poped[top])
            {
                st.pop();
                top++;
            }
        }
        if(st.empty()) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}